<!--销售开单-->
<div ms-controller="bill">
    <div >
        <!--<a class="pull-right" ms-click="close">关闭</a>-->
        <span ms-if='state=="sell"'>
            开具销售出库单
        </span>
        <span ms-if='state=="sellReturn"'>
            开具销售退货单
        </span>
        <span ms-if='state=="pur"'>
            开具采购入库单
        </span>
        <span ms-if='state=="purReturn"'>
             开具采购退货单
        </span>
        <span ms-if='state=="A"'>
             开具调拨单
        </span>
        <span ms-if='state=="-4"'>
             开具报损单
        </span>
        <span ms-if='state=="B"'>
             开具盘存单
        </span>

        <span ms-if='state=="quotation"'>
             开具销售报价单
        </span>
        <span ms-if="state=='goodsCar'" style="color:#5CA2B7;font-weight:bold;">
             备选商品
        </span>

        <button class="btn btn-xs btn-default" ms-if="state!='goodsCar'" ms-click="reset">重置表单</button>

    </div>

    <div class="sell-form" ms-if="state!='goodsCar'">
        <h2 class="text-center">
            <!--【乐山新宇电脑】--->
            <span ms-if='state=="sell"'>
                开具销售出库单
            </span>
            <span ms-if='state=="sellReturn"'>
                开具销售退货单
            </span>
            <span ms-if='state=="pur"'>
                开具采购入库单
            </span>
            <span ms-if='state=="purReturn"'>
                 开具采购退货单
            </span>
            <span ms-if='state=="A"'>
                 开具调拨单
            </span>
            <span ms-if='state=="-4"'>
                 开具报损单
            </span>
            <span ms-if='state=="B"'>
                 开具盘存单
            </span>
            <span ms-if='state=="quotation"'>
                 开具销售报价单
            </span>
        </h2>
        <br/>

        <div class="row">
            <div class="col-xs-4">
                <label>
                    开单时间：
                    <span>{{date|date("yyyy年 MMM dd日 HH:mm")}}</span>

                </label>

            </div>
            <div class="col-xs-4">

            </div>
            <div class="col-xs-4">
                <label>
                    单号：
                    <small>{{orderID}}</small>
                </label>
            </div>

        </div>

        <!-- 一般的交易单-->
        <div ms-if='state=="sell"||state=="sellReturn"||state=="pur"||state=="purReturn"||state=="quotation"'>
            <div class="row">
                <div class="col-xs-8">
                    <label>
                        <span ms-if='state=="sell"||state=="sellReturn"||state=="quotation"'>客户名称：</span>
                        <span ms-if='state=="pur"||state=="purReturn"'>供应商名称：</span>

                        <input type="text" maxlength="50" id="inputCus"
                               class="input-in-paper"
                               onkeyup="billCusSearch.posePanel(this)"
                               onfocus="billCusSearch.show(true);billCusSearch.posePanel(this)"
                               onblur="billCusSearch.show(false)"
                               onkeyup="cutLength(this)"
                               ms-duplex="customer.Name"
                               placeholder="客户搜索"/>
                    </label>
                    <!--客户查询的搜索结果框-->
                    <div class="live-search-goods"
                         ms-visible='(searching==-2||onGoods==-2)&&customer.Name!=""&&customerKey!=""'
                         ms-on-mouseenter="goHover(-2)" ms-on-mouseleave="goOut">
                        <div class="">
                            &nbsp;&nbsp;第{{CP}} &nbsp;/&nbsp; {{Math.ceil(CT/CN)}}页
                            <i class="icon-caret-right icon-2x search-pager pull-right" ms-if="CP<(Math.ceil(CT/CN))"
                               ms-click="pagerCus(-1)">&nbsp;&nbsp;</i>
                            <i class="icon-caret-left icon-2x search-pager pull-right" ms-if="CP>1"
                               ms-click="pagerCus(1)">&nbsp;&nbsp;</i>
                        </div>
                        <table class="table table-search">
                            <thead>
                            <tr>
                                <td>名称</td>
                                <td>应收款</td>
                                <td>应付款</td>
                            </tr>
                            </thead>
                            <tbody>

                            <tr ms-repeat="customers" ms-on-mouseenter="selectCustomer($index)"
                                ms-click="jump2Customer($index)" ms-class="now:focusCustomer==$index">
                                <td>{{el.Name}}</td>
                                <td>{{el.Receivables}}</td>
                                <td>{{el.Payable}}</td>
                            </tr>
                            </tbody>
                        </table>


                    </div>
                </div>

                <div class="col-xs-4">
                    <label>
                        联系方式：
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-paper"
                               ms-duplex="customer.Phone"/>
                    </label>
                </div>

            </div>
            <div class="row">
                <div class="col-xs-12">
                    <label>
                        地址：
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" onkeyup="cutLength(this)"
                               class="input-in-paper" style="width: 600px" ms-duplex="customer.Address"/>

                    </label>

                </div>


            </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <td></td>
                    <td style="min-width:50px">
                        编号
                    </td>
                    <td style="min-width:120px">
                        商品名称
                    </td>
                    <td style="min-width:120px">
                        条形码
                    </td>
                    <td style="min-width:100px">
                        规格
                    </td>
                    <td style="min-width:50px">
                        单位
                    </td>
                    <td style="min-width:50px">
                        数量
                    </td>
                    <td style="min-width:80px">
                        <span ms-if='state=="sell"||state=="quotation"'>单价</span>
                        <span ms-if='state=="pur"'>进价</span>
                        <span ms-if='state=="sellReturn"'>退货价</span>
                        <span ms-if='state=="purReturn"'>退货价</span>
                    </td>

                    <td style="width:80px">
                        小计
                    </td>
                    <td style="width:150px">
                        备注
                    </td>
                </tr>
                </thead>
                <tbody>


                <tr ms-repeat-el="List"  ms-class="delFocus:delFocusing==$index">
                    <td>
                <span
                      class="btn-xs btn btn-danger"
                      ms-on-mouseenter="delFocus($index)"
                      ms-on-mouseleave="delFocus(-1)"
                      ms-click="delRow($index)">
                    <i class="icon-minus-sign"></i>
                        删除
                </span>
                    </td>
                    <td>

                        {{$index+1}}

                    </td>
                    <td>
                        <input type="text" maxlength="50"
                               ms-on-focus-1="checkLast($last)"
                               class="input-in-table billInput"
                               ms-duplex="el.Name"
                               ms-on-focus="goodFocus($index)"
                               ms-on-blur="goodBlur(-1)"
                               ms-on-keydown-5="getIndex($index)"
                               onkeyup="billGoodsSearch.posePanel(this)"
                               onfocus="billGoodsSearch.show(true);billGoodsSearch.posePanel(this)"
                               onblur="billGoodsSearch.show(false)"
                               onkeyup="cutLength(this)"
                               placeholder="搜索商品"/>

                    </td>
                    <td>
                        {{el.BarCode}}
                    </td>
                    <td>
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table"
                               ms-duplex="el.Standard" ms-if='el.os==""'/>
                        <span ms-if='el.os!=""'>{{el.Standard}}</span>
                    </td>
                    <td>    <!--  ms-focus="unitFocus($index)" ms-blur="unitBlur"   -->
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table unitInput"
                               ms-duplex="el.Unit" ms-if='el.ou==""'/>
                        <span ms-if='el.ou!=""'>{{el.Unit}}</span>
                    </td>
                    <td style="position: relative">
                        <input type="number" maxlength="50" onkeyup="cutLength(this)" class="input-in-table numInput"
                               ms-duplex="el.Amount"
                               ms-focus="numFocus($index)" ms-blur="numBlur" ms-on-keyup="sum"
                               ms-on-keyup-2="amountErr($index)" ms-class="err:el.AmountErr"/>
                        <span class="label label-danger pull-right" ms-if="el.AmountErr"
                              style="position: absolute;top: 26px;left: 4px;">超库存</span>
                    </td>
                    <td style="position: relative">
                        <input type="number" maxlength="50" onkeyup="cutLength(this)" class="input-in-table priceInput"
                               ms-duplex="el.Price1" i
                               ms-focus="priceFocus($index)" ms-blur="priceBlur" ms-on-keyup="sum"
                               ms-on-keyup-2="priceErr($index)" ms-class="err:el.PriceErr"/>
                        <span class="label label-danger pull-right" ms-if="el.PriceErr"
                              style="position: absolute;top: 26px;left: 4px;">低于成本</span>
                    </td>

                    <td>
                        <input type="number" maxlength="50" onkeyup="cutLength(this)" class="input-in-table"
                               ms-duplex="el.sum" ms-on-keyup="backSum"/>
                    </td>
                    <td>
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table"
                               ms-duplex="el.Memo"/>
                    </td>

                </tr>
                <tr>
                    <td colspan="10" style="border: none">
                        <button class="btn btn-success btn-sm" ms-click="addRow(1)">
                            <i class="icon-plus"></i>
                            添加一栏
                        </button>
                    </td>
                </tr>


                </tbody>
                <tfoot>
                <tr>
                    <td>
                        总计
                    </td>
                    <td colspan="3">
                        人民币（大写）：

                        {{bigTotal}}
                    </td>
                    <td colspan="3">
                        小写:
                    </td>
                    <td colspan="3">
                        ￥{{Total}}
                    </td>

                </tr>
                </tfoot>
            </table>
            <!--<table class="table table-bordered" style="margin-top: -21px">-->
            <!--<tbody style="height: 30px">-->
            <!-- -->
            <!--</tbody>-->
            <!--</table>-->
            <div ms-if='state!="quotation"'>
                <div class="row">
                    <div class="col-xs-12">
                        <label style="color: #666666;font-weight: bold">
                            已付款：￥
                            <input type="number" class="input-in-paper" ms-duplex="pay"
                                   style="border-bottom: 1px solid #66a7bb"/>
                        </label>
                    </div>
                </div>
                <div class="box-row hor-ends warp">
                    <div >
                        <label>
                            <span ms-visible='state=="sell"||state=="purReturn"'>
                                出库仓库：
                            </span>
                            <span ms-visible='state=="sellReturn"||state=="pur"'>
                                入库仓库
                            </span>
                        <span>
                            {{Store.Name}}
                        </span>
                        </label>
                    </div>
                    <div >
                        <label>
                            开单人：
                        <span>
                            {{Operator}}
                        </span>
                        </label>
                    </div>


                        <div >
                            <label>
                                <span ms-if='state=="sell"||state=="purReturn"'>出库员：</span>
                                <span ms-if='state=="sellReturn"'>出库员: </span>
                                <span>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </span>
                            </label>
                        </div>

                        <div >
                            <label>
                                <span ms-if='state=="sell"'>客户签字：</span>
                                <span ms-if='state=="purReturn"'>收货人签字：</span>
                                <span>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </span>
                            </label>
                        </div>
                    <div ms-if='state=="pur"'>

                        <div >
                            <label>
                                库管人签字：
                        <span>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        </span>
                            </label>
                        </div>


                    </div>
                </div>



            </div>
        </div>

        <!-- 调拨单 以及报损 以及盘存-->
        <div ms-if='state=="A"||state=="-4"||state=="B"'>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <td style="width: 59px"></td>
                    <td style="width:50px">
                        编号
                    </td>
                    <td style="min-width:120px">
                        商品名称
                    </td>
                    <td style="min-width:120px">
                        条形码
                    </td>
                    <td style="min-width:100px">
                        规格
                    </td>
                    <td style="min-width:50px">
                        单位
                    </td>
                    <td ms-if='state=="B"' style="min-width:50px">
                        盘前
                    </td>
                    <td style="min-width:50px" ms-if='state!="B"'>
                        数量
                    </td>
                    <td style="min-width:50px" ms-if='state=="B"'>
                        实盘
                    </td>
                    <td ms-if='state=="B"' style="min-width:50px">
                        盈亏
                    </td>
                    <!--<td style="width:80px">-->
                    <!--单价-->
                    <!--</td>-->
                    <!---->
                    <!--<td style="width:80px">-->
                    <!--小计-->
                    <!--</td>-->
                    <td style="width:150px">
                        备注
                    </td>
                </tr>
                </thead>
                <tbody>


                <tr ms-repeat-el="List" ms-class="delFocus:delFocusing==$index">
                    <td>
                    <span class="btn-xs btn btn-danger" ms-on-mouseenter="delFocus($index)"
                          ms-on-mouseleave="delFocus(-1)" ms-click="delRow($index)">

                        删除

                    </span>
                    </td>
                    <td>
                        {{$index+1}}
                    </td>
                    <td><!--  tGoodInput    -->
                        <input type="text" maxlength="50" name="goodsInput"
                               class="input-in-table bill2Input"
                               ms-duplex="el.Name"
                               ms-on-focus="goodFocus($index)"
                               ms-on-focus-1="checkLast($last)"
                               ms-on-blur="goodBlur(-1)"
                               ms-on-keydown-5="getIndex($index)"
                               onkeyup="billGoodsSearch.posePanel(this)"
                               onfocus="billGoodsSearch.show(true);billGoodsSearch.posePanel(this)"
                               onblur="billGoodsSearch.show(false)"
                               onkeyup="cutLength(this)"
                               placeholder="搜索商品"/>
                    </td>
                    <td>
                        {{el.BarCode}}
                    </td>
                    <td>
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table"
                               ms-duplex="el.Standard" ms-if='el.os==""'/>
                        <span ms-if='el.os!=""'>{{el.Standard}}</span>
                    </td>
                    <td>
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table"
                               ms-duplex="el.Unit" ms-if='el.ou==""'/>
                        <span ms-if='el.ou!=""'>{{el.Unit}}</span>
                    </td>
                    <td ms-if='state=="B"'>
                        {{el.ThisTotle}}
                        <span ms-if="el.ThisTotle==0&&el.GoodsID!=0">0</span>
                    </td>
                    <td>
                        <input type="number" min="0" maxlength="50" onkeyup="cutLength(this)" class="input-in-table num2Input"
                               ms-duplex="el.Amount" ms-focus="numBlind2($index)" ms-blur="offNumBlind2"
                               ms-on-keyup="sum"/>
                    </td>
                    <!--<td>-->
                    <!--<input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table" ms-duplex="el.Price1"  ms-on-keyup="sum"/>-->
                    <!--</td>-->

                    <!--<td>-->
                    <!--<input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table" ms-duplex="el.sum"/>-->
                    <!--</td>-->

                    <td ms-if='state=="B"'>
                        <span ms-visible="el.Name!=''">
                            {{Number(el.Amount-el.ThisTotle).toFixed(3)}}
                        </span>

                    </td>
                    <td>
                        <input type="text" maxlength="50" onkeyup="cutLength(this)" class="input-in-table"
                               ms-duplex="el.Memo"/>
                    </td>

                </tr>
                <tr>
                    <td colspan="10" style="border: none">
                        <button class="btn btn-success btn-sm" ms-click="addRow(1)">
                            <i class="icon-plus"></i>
                            添加一栏
                        </button>
                    </td>
                </tr>

                </tbody>
            </table>

            <div ms-if='state=="A"'>

                <span>
                    <label>
                        <span class="pull-left">
                            出库库房：
                        </span>
                         <span>
                             {{Store.Name}}
                         </span>

                        <!--<select name="" ms-duplex="FromStoreID">-->
                        <!--<option value="">选择库房</option>-->
                        <!--<option ms-attr-value="el.StoreID" ms-repeat="Stores">{{el.Name}}</option>-->
                        <!--</select>-->
                        &nbsp;
                    </label>

                </span>
                <label>
                    <span class="pull-left">
                    入库库房：
                    </span>
                    <select name="" ms-duplex="ToStoreID" style="font-size: 14px">
                        <option value="">选择库房</option>
                        <option ms-attr-value="el.StoreID" ms-repeat="Stores">{{el.Name}}</option>
                    </select>
                    &nbsp;
                </label>

            </div>
            <div ms-if='state=="-4"||state=="B"'>
                <span>
                    <label>
                        <span class="pull-left">
                            库房：
                        </span>

                         <span>
                             {{Store.Name}}
                         </span>
                        &nbsp;
                    </label>
                </span>
            </div>
        </div>

        <!-- 盘存单-->

        <!-- 报损单-->

        <br/>
        <label style="width: 100%">
            订单备注：<br/>

            <input type="text" class="input-in-paper" ms-duplex="Memo"
                   style="border-bottom: 1px solid #66a7bb;width: 100%;"/>
        </label>

        <div ms-if='state=="A"||state=="B"||state=="-4"' style="height: 20px;"></div>


    </div>
    <div class="mo-footer"  ms-if="state!='goodsCar'">
        <label style="font-weight: normal;cursor: pointer" ms-if='state!="A"&&state!="B"&&state!="-4"'>
            <input type="checkbox" ms-click="toggleV()"/>
        <span>
            测试订单（不会影响库存信息，但会记录金额）
        </span>
        </label>

        <div class="pull-right">
            <button class="btn  btn-success " style="margin-right:39px" ms-click="exportQuotation" ms-if="state=='quotation'">
                导出
            </button>
            <button class="btn  btn-success " style="margin-right: 39px" ms-click="haveDone" ms-if="showBtn&&state!='quotation'">
                <i class="icon-shopping-cart"></i>
                开单
            </button>
            <span ms-if="!showBtn">正在开单……</span>
            <!--<button class="btn  btn-default " ms-click="close">取消</button>-->
        </div>
    </div>

    <!--<div ms-widget="tip,billTip"></div>-->
    <!--<tsy:tip config="btConfig"></tsy:tip>-->
</div>
